using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.TeamFoundation.WebAccess.WorkItemTracking.Controls;
using Microsoft.TeamFoundation.WorkItemTracking.Controls;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFSWorkflowControl.TSWA
{
    public static class WorkItemExtender
    {

        public static FieldDefinition GetField(this WorkItem workItem, string referenceName)
        {
            foreach (FieldDefinition fd in workItem.Type.FieldDefinitions)
            {
                if (fd.ReferenceName == referenceName)
                {
                    return fd;
                }
            }
            throw new InvalidOperationException(String.Format("{0} field not found!", referenceName));
        }

        public static string GetFieldValue(this Revision revision, string referenceName)
        {
            if (revision == null)
            {
                return null;
            }

            if (!revision.Fields.Contains(referenceName))
            {
                return null;
            }

            return revision.Fields[referenceName].Value.ToString();
        }

    }
}
